toStrictlyPositiveIntOrThrow
@ExperimentalSinceKotoolsTypes(version = "4.3.1")
Returns this number as a StrictlyPositiveInt, which may involve rounding or truncation, or throws IllegalArgumentException if this number is negative.
Here's some usage examples:
val result: StrictlyPositiveInt = 1.toStrictlyPositiveIntOrThrow()
println(result) // 1
0.toStrictlyPositiveIntOrThrow() // IllegalArgumentException
(-1).toStrictlyPositiveIntOrThrow() // IllegalArgumentException
Content copied to clipboard
You can use the toStrictlyPositiveIntOrNull function for returning null
instead of throwing an IllegalArgumentException when this number is negative.